import request from '@/utils/request'

export const userApi = {
  // 创建用户
  createUser: (user) => {
    return request.post('/api/users', user)
  },

  // 获取用户详情
  getUser: (id) => {
    return request.get(`/api/users/${id}`)
  },

  // 更新用户
  updateUser: (id, user) => {
    return request.put(`/api/users/${id}`, user)
  },

  // 删除用户
  deleteUser: (id) => {
    return request.delete(`/api/users/${id}`)
  },

  // 获取用户列表
  getUsers: (page = 1, size = 10) => {
    return request.get('/api/users', {
      params: { page, size }
    })
  },

  // 用户登录
  login: (username, password) => {
    return request.post('/api/users/login', {
      username,
      password
    })
  },

  // 用户登出
  logout: (userId) => {
    return request.post('/api/users/logout', {
      userId
    })
  },

  // 重置密码
  resetPassword: (username) => {
    return request.post('/api/users/password/reset', {
      username
    })
  },

  // 修改密码
  changePassword: (userId, oldPassword, newPassword) => {
    return request.put('/api/users/password', {
      userId,
      oldPassword,
      newPassword
    })
  },

  // 刷新token
  refreshToken: (refreshToken) => {
    return request.post('/api/users/token/refresh', {
      refreshToken
    })
  },

  // 获取角色的用户列表
  getRoleUsers: (roleId, page = 1, size = 10) => {
    return request.get(`/api/roles/${roleId}/users`, {
      params: { page, size }
    })
  },

  // 为用户分配角色
  assignRole: (roleId, userId) => {
    return request.post(`/api/roles/${roleId}/users`, {
      roleId,
      userId
    })
  },

  // 移除用户角色
  removeRole: (roleId, userId) => {
    return request.delete(`/api/roles/${roleId}/users/${userId}`)
  }
} 
 